MPL allows you import the elements for a data vector directly from a database. In the DATA section, where you define the data vector, enter the keyword DATABASE after the assignment symbol (:=), followed by parentheses containing the table name and the column/field name you want to import from.
Example:
DATA FactDepCost[factory,depot] := DATABASE("FactDep","TrCost");
In the above example, MPL will open the database table FactDep, locate the columns TRCost, actID, and DepotID, and then read in the entries for the data vector FactDepCost.
The FactDep Table:
FactID | DepotID | TrCost | Shipment |
---|---|---|---|
Houston | Chicago | 3200 | 0 |
Houston | Dallas | 5100 | 0 |
Seattle | Atlanta | 2800 | 0 |
Seattle | Chicago | 6800 | 0 |
Seattle | NewYork | 4700 | 0 |
Seattle | Dallas | 5400 | 0 |
Notice that MPL automatically uses the same name as the default for the index columns FactID and DepotID as in the original tables that the indexes were defined from. If an index column does have a different name than in the original table, you can specify it following the table name by first entering the index name, followed by an equal sign and the column name.
DATA FactDepCost[factory,depot] := DATABASE("FactDep","TrCost",factory="Factory",depot="Depot");
This means if you are consistent in naming the columns in different tables you do not have to specify them each time you refer to them in MPL.
The column name defaults to the name of the data vector, so if it is the same you do not have to specify it. In the example below the column name in the database table is TrCost which is the same as the data vector TrCost.
DATA TrCost := DATABASE("FactDep");
MPL can import from more than one database in the same run. The default database is specified in the Database Options dialog box in the Options menu. If you need to import a data vector from table in a database other than the default, you can do so by specifying the database name before the name of the table.
In the example below, MPL will read in the data vector DepotCustCost from Access instead of the default database.
DATA DepotCustCost := DATABASE(Access,"DepCust","TrCost");